package com.sxhuayuan.parking.plugin.parking.dahua.result;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class DaHuaResult {

    public final static String SUCCESS = "000000";
    public final static String FAIL = "999999";

    private String resCode;
    private String resMsg;
    private Object data;

    private final static DaHuaResult success;
    private final static DaHuaResult fail;
    public final static String CAR_BEFORE_OUT_FAIL_JSON;

    static{
        success = new DaHuaResult(SUCCESS, "请求成功");
        fail = new DaHuaResult(FAIL, "请求失败");
        JSONObject failJson = new JSONObject();
        failJson.put("amountReceivable", "0");
        failJson.put("amountActual", "0");
        failJson.put("isOpen", "2");
        failJson.put("isPayByLineAmount", "2");
        failJson.put("remark", "");
        CAR_BEFORE_OUT_FAIL_JSON =  DaHuaResult.successJson(failJson);

    }

    private DaHuaResult(String resCode, String resMsg){
        this.resCode = resCode;
        this.resMsg = resMsg;
    }

    public static DaHuaResult success(){
        return success;
    }

    public static String successJson(){
        return JSONObject.toJSONString(success);
    }

    public static DaHuaResult success(Object data){
        return new DaHuaResult(SUCCESS, "请求成功", data);
    }

    public static String successJson(Object data){
        return JSONObject.toJSONString(success(data));
    }

    public static DaHuaResult fail(){
        return fail;
    }

    public static String failJson(){
        return JSONObject.toJSONString(fail);
    }

    public static DaHuaResult fail(String resMsg){
        return new DaHuaResult(FAIL, resMsg);
    }

    public static String failJson(String resMsg){
        return JSONObject.toJSONString(fail(resMsg));
    }

     /**
     * 出厂前推送 用来哦控制抬杆的, 不过貌似不管用
     * @param amountReceivable 应缴金额
     * @param amountActual 实缴金额
     * @return
     */
//    public static String successJsonCarBeforeOutOpen(String amountReceivable, String amountActual){
//        JSONObject successJson = new JSONObject();
//        successJson.put("amountReceivable", amountReceivable);
//        successJson.put("amountActual", amountActual);
//        successJson.put("isOpen", "1");
//        successJson.put("isPayByLineAmount", "1");
//        successJson.put("remark", "");
//        return successJson(successJson);
//    }

}
